import { BrowserWindow, ipcMain, type IpcMainInvokeEvent } from 'electron'

// 窗口移动事件
ipcMain.handle('win-move', (event: IpcMainInvokeEvent, position: { x: number; y: number }) => {
  const browserWindow = BrowserWindow.fromWebContents(event.sender)
  browserWindow?.setPosition(position.x, position.y)
})

// 窗口移动事件
ipcMain.handle('win-drag', (event: IpcMainInvokeEvent, opt: { x: number; y: number }) => {
  const browserWindow = BrowserWindow.fromWebContents(event.sender)!
  // 获取当前窗口的坐标
  const [x, y] = browserWindow.getPosition()
  // 设置上一次点位的差值
  browserWindow.setPosition(x + opt.x, y + opt.y)
})
